﻿using System;
using System.Windows.Controls;
using System.Windows.Threading;
using nRoute.ViewServices;
using Orktane.Sample.ConsoleApp.ViewServices;
using System.Windows.Media.Imaging;

namespace Orktane.Sample.ConsoleApp
{
    [MapViewService(typeof(IWallpaperViewService), Lifetime = ViewServiceLifetime.DiscoveredInstance)]
    public partial class MainPage 
        : UserControl, IWallpaperViewService
    {
        private DispatcherTimer _timer;

        public MainPage()
        {
            InitializeComponent();
            SetupTimer();
        }

#region IWallpaperViewService Members

        public void SetWallpaper(BitmapSource source)
        {
            this.Wallpaper.Source = source;
        }

#endregion

#region Helpers

        private void SetupTimer()
        {
            // timer
            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMinutes(1d);
            _timer.Tick += (s, e) => TimeText.Text = DateTime.Now.ToString("hh:mm tt");
            _timer.Start();

            // update time
            TimeText.Text = DateTime.Now.ToString("hh:mm tt");
        }

#endregion

    }
}
